package com.neusoft.edu.smartschool.app.db.sp;

import android.content.Context;
import android.util.Base64;
import android.util.Log;

import com.google.gson.Gson;
import com.neusoft.edu.smartschool.app.db.Const;
import com.neusoft.edu.smartschool.app.entity.UserBean;

import org.yeruyi.common.db.RoyBaseSp;

/**
 * @author: yeruyi
 * @date: 2018/5/29
 * @email: yeruyi_roy@outlook.com
 * @modify: 2018/5/29 创建文件
 */
public class UserSp extends RoyBaseSp {

    private final String NAME_USER_BEAN = "nub";

    private UserSp(Context context) {
        super(context);
    }

    @Override
    protected String getSpName() {
        return Const.ConstSp.SP_USER;
    }

    private static UserSp INSTANCE;

    public static UserSp getInstance(Context context) {
        if (INSTANCE == null) {
            INSTANCE = new UserSp(context);
        }
        return INSTANCE;
    }

    public void setUserBean(UserBean userBean) {
        String str = new Gson().toJson(userBean);
        String enStr = new String(Base64.encode(str.getBytes(), Base64.DEFAULT));
        Log.d(TAG, "setUserBean:[加密前]:" + str);
        Log.d(TAG, "setUserBean:[加密后]:" + enStr);
        putData(NAME_USER_BEAN, enStr);
    }


}
